package com.yida.gwj.expend.service.impl;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson2.JSONObject;
import com.yida.common.core.constant.SecurityConstants;
import com.yida.common.core.domain.R;
import com.yida.common.core.exception.ServiceException;
import com.yida.common.core.utils.DateUtils;
import com.yida.common.core.utils.PageUtils;
import com.yida.common.core.utils.StringUtils;
import com.yida.common.security.utils.SecurityUtils;
import com.yida.gwj.api.domain.GwjConfBusinessFlag;
import com.yida.gwj.api.domain.GwjConfFlow;
import com.yida.gwj.api.domain.GwjConfStep;
import com.yida.gwj.api.domain.GwjFinanceAccountDetail;
import com.yida.gwj.api.domain.GwjFinanceAccountMain;
import com.yida.gwj.api.domain.GwjFinanceBank;
import com.yida.gwj.api.domain.request.RemoteGwjFinanceAccountDetailRequest;
import com.yida.gwj.api.domain.request.RemoteGwjFinanceAccountMainRequest;
import com.yida.gwj.api.service.RemoteGwjConfigService;
import com.yida.gwj.api.service.RemoteGwjExpendService;
import com.yida.gwj.api.service.RemoteGwjFinanceService;
import com.yida.gwj.common.enums.GwjBusinessFlagType;
import com.yida.gwj.common.enums.GwjBusinessLogResult;
import com.yida.gwj.common.enums.GwjCheckAccountStatus;
import com.yida.gwj.common.enums.GwjCheckAccountType;
import com.yida.gwj.common.enums.StepConfigInfoEnum;
import com.yida.gwj.common.utils.BigDecimalUtils;
import com.yida.gwj.common.utils.GwjEnumUtils;
import com.yida.gwj.expend.annotation.ConfStepConfigCheck;
import com.yida.gwj.expend.domain.GwjMaintenanceFundsBusiness;
import com.yida.gwj.expend.domain.GwjMaintenanceFundsBusinessAttachment;
import com.yida.gwj.expend.domain.GwjMaintenanceFundsBusinessCommunity;
import com.yida.gwj.expend.domain.GwjMaintenanceFundsBusinessHouse;
import com.yida.gwj.expend.domain.GwjMaintenanceFundsBusinessInfo;
import com.yida.gwj.expend.domain.GwjMaintenanceFundsBusinessLog;
import com.yida.gwj.expend.domain.dto.AcceptanceReportDTO;
import com.yida.gwj.expend.domain.dto.AllocatedAmountListDTO;
import com.yida.gwj.expend.domain.dto.AllocatedAmountSelectDTO;
import com.yida.gwj.expend.domain.dto.Application4ApprovalDTO;
import com.yida.gwj.expend.domain.dto.ApplyAppropriateReportDTO;
import com.yida.gwj.expend.domain.dto.Appropriate4ApproveDTO;
import com.yida.gwj.expend.domain.dto.ConfirmReceiptDTO;
import com.yida.gwj.expend.domain.dto.CostListDTO;
import com.yida.gwj.expend.domain.dto.GwjMaintenanceFundsBusinessGetInfoDTO;
import com.yida.gwj.expend.domain.dto.GwjMaintenanceFundsBusinessListDTO;
import com.yida.gwj.expend.domain.dto.OneTimeNotificationDTO;
import com.yida.gwj.expend.domain.dto.StepConfigInfoDTO;
import com.yida.gwj.expend.domain.dto.TotalCostShareListDTO;
import com.yida.gwj.expend.domain.message.PreAcceptSubmitMessage;
import com.yida.gwj.expend.domain.request.AcceptanceReportRequest;
import com.yida.gwj.expend.domain.request.AllocatedAmountRequest;
import com.yida.gwj.expend.domain.request.ApplyAppropriateReportRequest;
import com.yida.gwj.expend.domain.request.BusinessProcessRequest;
import com.yida.gwj.expend.domain.request.EditFormRequest;
import com.yida.gwj.expend.domain.request.GwjMaintenanceFundsBusinessListRequest;
import com.yida.gwj.expend.domain.request.SubmitRequest;
import com.yida.gwj.expend.domain.request.TotalCostShareListRequest;
import com.yida.gwj.expend.enums.AppropriationWayEnum;
import com.yida.gwj.expend.enums.BusinessAttachmentServerTypeEnum;
import com.yida.gwj.expend.enums.BusinessAttachmentTypeEnum;
import com.yida.gwj.expend.enums.BusinessServerStatusEnum;
import com.yida.gwj.expend.enums.BusinessStatusEnum;
import com.yida.gwj.expend.enums.BusinessTypeEnum;
import com.yida.gwj.expend.enums.FlagStatusEnum;
import com.yida.gwj.expend.enums.MaintenanceFundsErrorEnum;
import com.yida.gwj.expend.enums.SelectFlagEnum;
import com.yida.gwj.expend.service.IGwjMaintenanceFundsBusinessAppropriateService;
import com.yida.gwj.expend.service.IGwjMaintenanceFundsBusinessAttachmentService;
import com.yida.gwj.expend.service.IGwjMaintenanceFundsBusinessCommunityService;
import com.yida.gwj.expend.service.IGwjMaintenanceFundsBusinessHouseService;
import com.yida.gwj.expend.service.IGwjMaintenanceFundsBusinessInfoService;
import com.yida.gwj.expend.service.IGwjMaintenanceFundsBusinessLogService;
import com.yida.gwj.expend.service.IGwjMaintenanceFundsBusinessService;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.comparator.CompareUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;

/**
 * 公维金维修资金业务Service业务层处理
 *
 * @author lgp
 * @date 2023-02-20
 */
@Service
public class GwjMaintenanceFundsBusinessAppropriateServiceImpl implements IGwjMaintenanceFundsBusinessAppropriateService {

    private final Logger log = LoggerFactory.getLogger(GwjMaintenanceFundsBusinessAppropriateServiceImpl.class);

    @Autowired
    private IGwjMaintenanceFundsBusinessService maintenanceFundsBusinessService;
    @Autowired
    private IGwjMaintenanceFundsBusinessInfoService maintenanceFundsBusinessInfoService;
    @Autowired
    private IGwjMaintenanceFundsBusinessHouseService maintenanceFundsBusinessHouseService;
    @Autowired
    private IGwjMaintenanceFundsBusinessAttachmentService maintenanceFundsBusinessAttachmentService;
    @Autowired
    private RemoteGwjConfigService remoteGwjConfigService;
    @Autowired
    private RemoteGwjFinanceService remoteGwjFinanceService;
    @Autowired
    private IGwjMaintenanceFundsBusinessCommunityService maintenanceFundsBusinessCommunityService;
    @Autowired
    private IGwjMaintenanceFundsBusinessLogService maintenanceFundsBusinessLogService;

    @Autowired
    private RemoteGwjExpendService remoteGwjExpendService;

    @Override
    public List<GwjMaintenanceFundsBusinessListDTO> getGwjMaintenanceFundsBusinessList(GwjMaintenanceFundsBusinessListRequest maintenanceFundsBusinessListRequest) {
        return maintenanceFundsBusinessService.getGwjMaintenanceFundsBusinessList(maintenanceFundsBusinessListRequest);
    }

    @Override
    public GwjMaintenanceFundsBusinessGetInfoDTO getInfoDetails(Long businessId) {
        return maintenanceFundsBusinessService.getInfoDetails(businessId);
    }

    @Override
    public GwjConfFlow selectGwjConfFlowByFlowId(Long flowId) {
        return maintenanceFundsBusinessService.selectGwjConfFlowByFlowId(flowId);
    }

    @Override
    public int takeParts(BusinessProcessRequest businessProcessRequest) {
        return maintenanceFundsBusinessService.takeParts(businessProcessRequest);
    }

    @Override
    public int preAcceptRetreat(BusinessProcessRequest businessProcessRequest) {
        return maintenanceFundsBusinessService.preAcceptRetreat(businessProcessRequest);
    }

    @Override
    public List<GwjMaintenanceFundsBusinessHouse> allocatedAmountCancelList(AllocatedAmountRequest allocatedAmountRequest) {
        return maintenanceFundsBusinessService.allocatedAmountCancelList(allocatedAmountRequest);
    }

    @ConfStepConfigCheck(bizId = "#bizId", stepConfigInfo = {StepConfigInfoEnum.EXAMINE}, businessStatus = {BusinessStatusEnum.TAKE_PARTS})
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int preAcceptExamine(Long bizId) {
        GwjMaintenanceFundsBusiness maintenanceFundsBusiness = maintenanceFundsBusinessService.selectGwjMaintenanceFundsBusinessByBusinessId(bizId);
        if (ObjectUtil.isNull(maintenanceFundsBusiness)) {
            throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.PRE_ACCEPT_EXAMINE) + "未获取到公共维修资金业务对象GwjMaintenanceFundsBusiness");
        }
        Optional.ofNullable(maintenanceFundsBusinessService.updateGwjMaintenanceFundsBusiness(new GwjMaintenanceFundsBusiness() {
            {
                setBizId(maintenanceFundsBusiness.getBizId());
                setStatus(BusinessStatusEnum.APPROVED.getCode());
                setServerStatus(BusinessServerStatusEnum.FINISH.getCode());
                try {
                    R<GwjConfStep> r = remoteGwjConfigService.getFinalStep(maintenanceFundsBusiness.getBizFlagId(), SecurityConstants.INNER);
                    if (R.isError(r)) {
                        throw new ServiceException(r.getMsg());
                    }
                    if (ObjectUtil.isNull(r.getData())) {
                        throw new ServiceException(r.getMsg());
                    }
                    setStepId(r.getData().getStepId());
                } catch (Exception e) {
                    log.error("远程调用 -> [remoteGwjConfigService][getFinalStep]异常,异常信息: [{}]", e);
                    throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.PRE_ACCEPT_EXAMINE) + "远程调用 -> [remoteGwjConfigService][getFinalStep]异常");
                }
            }
        })).<ServiceException>orElseThrow(() -> {
            throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.PRE_ACCEPT_EXAMINE) + "公共维修资金业务对象GwjMaintenanceFundsBusiness更新失败");
        });
        Optional.of(maintenanceFundsBusinessService.delete4Save((businessId) -> {
            PreAcceptSubmitMessage preAcceptSubmitMessage = maintenanceFundsBusinessService.getBusinessModules(businessId);
            GwjMaintenanceFundsBusiness maintenanceFundsBusiness1 = preAcceptSubmitMessage.getMaintenanceFundsBusiness();
            maintenanceFundsBusiness1.setBizId(null);
            maintenanceFundsBusiness1.setCurrentOperId(null);
            maintenanceFundsBusiness1.setCurrentOperName(null);
            maintenanceFundsBusiness1.setCreateTime(DateTime.now());
            maintenanceFundsBusiness1.setUpdateTime(DateTime.now());
            maintenanceFundsBusiness1.setCreateBy(maintenanceFundsBusiness.getCreateBy());
            maintenanceFundsBusiness1.setUpdateBy(maintenanceFundsBusiness.getCreateBy());
            maintenanceFundsBusiness1.setStatus(BusinessStatusEnum.SUBMIT.getCode());
            maintenanceFundsBusiness1.setServerStatus(BusinessServerStatusEnum.NORMAL.getCode());
            // 外网业务标识关联
            maintenanceFundsBusiness1.setOutServerIdentification(maintenanceFundsBusiness.getOutServerIdentification());
            maintenanceFundsBusiness1.setServerIdentification(IdUtil.getSnowflakeNextIdStr());
            switch (BusinessTypeEnum.transfer(maintenanceFundsBusiness.getType())) {
                case APPROPRIATE_PREPARE:
                    maintenanceFundsBusiness1.setType(BusinessTypeEnum.APPROPRIATE_FORMAL.getCode());
                    maintenanceFundsBusiness1.setBizFlagId(GwjBusinessFlagType.EXPEND_APPROPRIATE_FORMAL.getCode());
                    break;
                case URGENT_APPROPRIATE_PREPARE:
                    maintenanceFundsBusiness1.setType(BusinessTypeEnum.URGENT_APPROPRIATE_FORMAL.getCode());
                    maintenanceFundsBusiness1.setBizFlagId(GwjBusinessFlagType.EXPEND_URGENT_APPROPRIATE_FORMAL.getCode());
                    break;
                default:
                    break;
            }
            try {
                R<GwjConfBusinessFlag> r = remoteGwjConfigService.selectGwjConfBusinessFlagByBizFlagId(maintenanceFundsBusiness1.getBizFlagId(), SecurityConstants.INNER);
                if (R.isError(r)) {
                    throw new ServiceException(r.getMsg());
                }
                if (ObjectUtil.isNull(r.getData())) {
                    throw new ServiceException(r.getMsg());
                }
                maintenanceFundsBusiness1.setFlowId(r.getData().getFlowId());
            } catch (Exception e) {
                log.error("远程调用 -> [remoteGwjConfigService][selectGwjConfBusinessFlagByBizFlagId]异常,异常信息: [{}]", e);
                throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.PRE_ACCEPT_EXAMINE) + "远程调用 -> [remoteGwjConfigService][selectGwjConfBusinessFlagByBizFlagId]异常");
            }
            try {
                R<GwjConfStep> r = remoteGwjConfigService.getFirstStep(maintenanceFundsBusiness1.getBizFlagId(), SecurityConstants.INNER);
                if (R.isError(r)) {
                    throw new ServiceException(r.getMsg());
                }
                if (ObjectUtil.isNull(r.getData())) {
                    throw new ServiceException(r.getMsg());
                }
                maintenanceFundsBusiness1.setStepId(r.getData().getStepId());
            } catch (Exception e) {
                log.error("远程调用 -> [remoteGwjConfigService][getFirstStep]异常,异常信息: [{}]", e);
                throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.PRE_ACCEPT_EXAMINE) + "远程调用 -> [remoteGwjConfigService][getFirstStep]异常");
            }
            return Optional.of(preAcceptSubmitMessage);
        }, maintenanceFundsBusiness.getBizId()).<ServiceException>orElseThrow(() -> {
            throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.PRE_ACCEPT_EXAMINE) + "delete4Save异常");
        }));
        int insertFlag = maintenanceFundsBusinessLogService.insertGwjMaintenanceFundsBusinessLog(new GwjMaintenanceFundsBusinessLog() {
            {
                setBizId(maintenanceFundsBusiness.getBizId());
                setStepId(maintenanceFundsBusiness.getStepId());
                setResult(GwjBusinessLogResult.PASS.getCode());
            }
        });
        if (ObjectUtil.equal(FlagStatusEnum.FAL.getCode(), insertFlag)) {
            throw new ServiceException("GwjMaintenanceFundsBusinessLog新增失败");
        }
        insertFlag = maintenanceFundsBusinessLogService.insertGwjMaintenanceFundsBusinessLog(new GwjMaintenanceFundsBusinessLog() {
            {
                setBizId(maintenanceFundsBusiness.getBizId());
                setResult(GwjBusinessLogResult.FINISH.getCode());
                setAcceptTime(LocalDateTimeUtil.offset(LocalDateTime.now(), 1, ChronoUnit.SECONDS));
                try {
                    R<GwjConfStep> r = remoteGwjConfigService.getFinalStep(maintenanceFundsBusiness.getBizFlagId(), SecurityConstants.INNER);
                    if (R.isError(r)) {
                        throw new ServiceException(r.getMsg());
                    }
                    if (ObjectUtil.isNull(r.getData())) {
                        throw new ServiceException(r.getMsg());
                    }
                    setStepId(r.getData().getStepId());
                } catch (Exception e) {
                    log.error("远程调用 -> [remoteGwjConfigService][getFirstStep]异常,异常信息: [{}]", e);
                    throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.PRE_ACCEPT_EXAMINE) + "远程调用 -> [remoteGwjConfigService][getFirstStep]异常");
                }
            }
        });
        if (ObjectUtil.equal(FlagStatusEnum.FAL.getCode(), insertFlag)) {
            throw new ServiceException("GwjMaintenanceFundsBusinessLog新增失败");
        }
        return FlagStatusEnum.SUC.getCode();
    }

    @Override
    public StepConfigInfoDTO getStepConfigInfo(GwjBusinessFlagType... businessFlagTypes) {
        return maintenanceFundsBusinessService.getStepConfigInfo(businessFlagTypes);
    }

    @Override
    public int confirmAcceptance(SubmitRequest submitRequest) {
        return maintenanceFundsBusinessService.confirmAcceptance(submitRequest);
    }

    @Override
    public AllocatedAmountSelectDTO allocatedAmountSelect(AllocatedAmountRequest allocatedAmountRequest) {
        return maintenanceFundsBusinessService.allocatedAmountSelect(allocatedAmountRequest);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int submit(SubmitRequest submitRequest) {
        GwjMaintenanceFundsBusiness maintenanceFundsBusiness = maintenanceFundsBusinessService.selectGwjMaintenanceFundsBusinessByBusinessId(submitRequest.getBizId());
        if (ObjectUtil.isNull(maintenanceFundsBusiness)) {
            throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.SUBMIT) + "GwjMaintenanceFundsBusiness为空");
        }
        // 去掉参数内的空判断，这里新增判断防止空指针 hmh 20230712 start
        if (StringUtils.isNull(submitRequest.getStatus())) {
            throw new ServiceException("业务状态不能为空！");
        }
        // end
        if (ObjectUtil.notEqual(maintenanceFundsBusiness.getStatus(), submitRequest.getStatus())) {
            throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.SUBMIT) + "业务状态不一致,请重新提交");
        }
        BusinessStatusEnum statusEnum;
        switch (BusinessStatusEnum.transfer(submitRequest.getStatus())) {
            // 1.受理阶段需要确认是否收件
            case TAKE_PARTS:
                try {
                    List<BusinessAttachmentServerTypeEnum> noServerTypeEnum = maintenanceFundsBusinessAttachmentService.checkNull(() -> {
                        List<GwjMaintenanceFundsBusinessAttachment> maintenanceFundsBusinessAttachmentList = maintenanceFundsBusinessAttachmentService.selectGwjMaintenanceFundsBusinessAttachmentList(new GwjMaintenanceFundsBusinessAttachment() {
                            {
                                setServerIdentification(maintenanceFundsBusiness.getServerIdentification());
                            }
                        });
                        return Optional.of(maintenanceFundsBusinessAttachmentList);
                    }, true, BusinessAttachmentServerTypeEnum.getAppropriateServerTypeList());
                    if (CollectionUtil.isNotEmpty(noServerTypeEnum)) {
                        throw new ServiceException("附件" + noServerTypeEnum.get(0).getInfo() + "未收件,请先确认收件");
                    }
                } catch (Exception e) {
                    throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.SUBMIT) + e.getMessage());
                }
                statusEnum = BusinessStatusEnum.FIRST_INSTANCE;
                // ---------------------------202300904取消步骤回调 s--------------------------------------
                // 发送外网步骤回调
                // String takePartsJsonMsg = maintenanceFundsBusinessService.resultNotify(maintenanceFundsBusiness);
                // if (ObjectUtil.isEmpty(takePartsJsonMsg)) {
                // throw new ServiceException("公维金支出外网回调步骤参数不能为空");
                // }
                // // 步骤回调修改为远程调用
                // try {
                // remoteGwjExpendService.resultNotify(takePartsJsonMsg, SecurityConstants.INNER).getData();
                // } catch (Exception e) {
                // throw new
                // ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.CONFIRM_ACCEPTANCE) +
                // "支出外网步骤回调一次:" + e.getMessage());
                // }
                // ---------------------------202300904取消步骤回调 e--------------------------------------
                break;
            // 2.初审提交阶段
            case FIRST_INSTANCE:
                statusEnum = BusinessStatusEnum.REEXAMINE;
                // ---------------------------20230829取消步骤回调 s--------------------------------------
                // 发送外网步骤回调
                // String firstInstanceJsonMsg = maintenanceFundsBusinessService.resultNotify(maintenanceFundsBusiness);
                // if (ObjectUtil.isEmpty(firstInstanceJsonMsg)) {
                // throw new ServiceException("公维金支出外网回调步骤参数不能为空");
                // }
                // // 步骤回调修改为远程调用
                // try {
                // remoteGwjExpendService.resultNotify(firstInstanceJsonMsg, SecurityConstants.INNER).getData();
                // } catch (Exception e) {
                // throw new
                // ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.CONFIRM_ACCEPTANCE) +
                // "支出外网步骤回调一次:" + e.getMessage());
                // }
                // ---------------------------20230829取消步骤回调 e--------------------------------------
                break;
            // 2.复审提交阶段
            case REEXAMINE:
                // 判断是否生成财务流水
                if (ObjectUtil.equal(FlagStatusEnum.FAL.getCode(), maintenanceFundsBusiness.getFinancialJournalFlag())) {
                    throw new ServiceException("请先生成财务流水");
                }
                statusEnum = BusinessStatusEnum.FINANCE_CHECK;
                // ---------------------------20230829取消步骤回调 s--------------------------------------
                // 发送外网步骤回调
                // String reexamineJsonMsg = maintenanceFundsBusinessService.resultNotify(maintenanceFundsBusiness);
                // if (ObjectUtil.isEmpty(reexamineJsonMsg)) {
                // throw new ServiceException("公维金支出外网回调步骤参数不能为空");
                // }
                // // 步骤回调修改为远程调用
                // try {
                // remoteGwjExpendService.resultNotify(reexamineJsonMsg, SecurityConstants.INNER).getData();
                // } catch (Exception e) {
                // throw new
                // ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.CONFIRM_ACCEPTANCE) +
                // "支出外网步骤回调一次:" + e.getMessage());
                // }
                // ---------------------------20230829取消步骤回调 e--------------------------------------
                break;
            // 3.财务对账阶段
            case FINANCE_CHECK:
                // 支出明细跟总支出比对: 分摊总金额=明细总支出
                GwjMaintenanceFundsBusinessInfo maintenanceFundsBusinessInfo = maintenanceFundsBusinessInfoService.selectGwjMaintenanceFundsBusinessInfoByBusinessId(maintenanceFundsBusiness.getBizId());
                // 判断是否进行财务对账
                if (!GwjCheckAccountStatus.CHECK_SUCCESS.getCode().equals(String.valueOf(maintenanceFundsBusiness.getFinanceCheck()))) {
                    throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.SUBMIT) + "请先完成财务对账后提交");
                }

                List<GwjMaintenanceFundsBusinessHouse> maintenanceFundsBusinessHouseList = maintenanceFundsBusinessHouseService.selectGwjMaintenanceFundsBusinessHouseList(new GwjMaintenanceFundsBusinessHouse() {
                    {
                        setSelectFlag(SelectFlagEnum.SELECT.getCode());
                        setBizId(maintenanceFundsBusiness.getBizId());
                    }
                });
                BigDecimal actualAllocationMoney = maintenanceFundsBusinessHouseList.stream().map(house -> house.getActualAllocationMoney()).reduce(BigDecimal.ZERO, BigDecimal::add);
                if (ObjectUtil.notEqual(maintenanceFundsBusinessInfo.getActualAllocationAmount(), actualAllocationMoney)) {
                    throw new ServiceException("决算总金额和明细支出总金额不一致,请重新提交");
                }
                // 总支出跟总账流水支出金额比对:决算总金额=总账流水支出金额
                BigDecimal payMoney = BigDecimal.ZERO;
                try {
                    R<GwjFinanceAccountMain> r = remoteGwjFinanceService.getGwjFinanceAccountMain(new GwjFinanceAccountMain() {
                        {
                            setBizId(maintenanceFundsBusiness.getBizId());
                            setBizNum(maintenanceFundsBusiness.getBizNum());
                            setBizFlagId(maintenanceFundsBusiness.getBizFlagId());
                        }
                    }, SecurityConstants.INNER);
                    if (R.isError(r)) {
                        throw new ServiceException(r.getMsg());
                    }
                    if (ObjectUtil.isNull(r.getData())) {
                        throw new ServiceException(r.getMsg());
                    }
                    payMoney = r.getData().getPayMoney();
                } catch (Exception e) {
                    log.error("远程调用 -> [remoteGwjFinanceService][getGwjFinanceAccountMain]异常,异常信息: [{}]", e);
                    throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.PRE_ACCEPT_EXAMINE) + "远程调用 -> [remoteGwjFinanceService][getGwjFinanceAccountMain]异常");
                }
                if (ObjectUtil.notEqual(maintenanceFundsBusinessInfo.getActualAllocationAmount(), payMoney)) {
                    throw new ServiceException("决算总金额和总账流水支出金额不一致,请重新提交");
                }
                // 明细账跟总账比对
                List<GwjFinanceAccountDetail> financeAccountDetailList;
                try {
                    R<List<GwjFinanceAccountDetail>> r = remoteGwjFinanceService.getGwjFinanceAccountDetailList(new RemoteGwjFinanceAccountDetailRequest() {
                        {
                            setBizId(maintenanceFundsBusiness.getBizId());
                            setBizNum(maintenanceFundsBusiness.getBizNum());
                            setBizFlagId(maintenanceFundsBusiness.getBizFlagId());
                        }
                    }, SecurityConstants.INNER);
                    if (R.isError(r)) {
                        throw new ServiceException(r.getMsg());
                    }
                    if (ObjectUtil.isNull(r.getData()) || CollectionUtil.isEmpty(r.getData())) {
                        throw new ServiceException("数据为空");
                    }
                    financeAccountDetailList = r.getData();
                } catch (Exception e) {
                    log.error("远程调用 -> [remoteGwjFinanceService][getGwjFinanceAccountDetailList]异常,异常信息: [{}]", e);
                    throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.PRE_ACCEPT_EXAMINE) + "远程调用 -> [remoteGwjFinanceService][getGwjFinanceAccountDetailList]异常");
                }
                BigDecimal payMoneyDetail = financeAccountDetailList.stream().map(detail -> detail.getPayMoney()).reduce(BigDecimal.ZERO, BigDecimal::add);
                if (ObjectUtil.notEqual(payMoney, payMoneyDetail)) {
                    throw new ServiceException("总账流水支出金额和明细流水支出总金额不一致,请重新提交");
                }
                try {
                    R<Integer> r = remoteGwjFinanceService.updateGwjFinanceAccountMain(new GwjFinanceAccountMain() {
                        {
                            setBizId(maintenanceFundsBusiness.getBizId());
                            setBizNum(maintenanceFundsBusiness.getBizNum());
                            setBizFlagId(maintenanceFundsBusiness.getBizFlagId());
                            setCheckStatus(GwjCheckAccountStatus.CHECK_SUCCESS.getCode());
                        }
                    }, SecurityConstants.INNER);
                    if (R.isError(r)) {
                        throw new ServiceException(r.getMsg());
                    }
                    if (ObjectUtil.equal(FlagStatusEnum.FAL.getCode(), r.getData())) {
                        throw new ServiceException(r.getMsg());
                    }
                } catch (Exception e) {
                    log.error("远程调用 -> [remoteGwjFinanceService][updateGwjFinanceAccountMain]异常,异常信息: [{}]", e);
                    throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.SUBMIT) + "远程调用 -> [remoteGwjFinanceService][updateGwjFinanceAccountMain]异常");
                }
                try {
                    R<Integer> r = remoteGwjFinanceService.updateGwjFinanceAccountDetail(new GwjFinanceAccountDetail() {
                        {
                            setBizId(maintenanceFundsBusiness.getBizId());
                            setBizNum(maintenanceFundsBusiness.getBizNum());
                            setBizFlagId(maintenanceFundsBusiness.getBizFlagId());
                            setCheckStatus(GwjCheckAccountStatus.CHECK_SUCCESS.getCode());
                        }
                    }, SecurityConstants.INNER);
                    if (R.isError(r)) {
                        throw new ServiceException(r.getMsg());
                    }
                    if (ObjectUtil.equal(FlagStatusEnum.FAL.getCode(), r.getData())) {
                        throw new ServiceException(r.getMsg());
                    }
                } catch (Exception e) {
                    log.error("远程调用 -> [remoteGwjFinanceService][updateGwjFinanceAccountDetail]异常,异常信息: [{}]", e);
                    throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.SUBMIT) + "远程调用 -> [remoteGwjFinanceService][updateGwjFinanceAccountDetail]异常");
                }
                statusEnum = BusinessStatusEnum.FINISH;
                // ---------------------------20230829取消步骤回调 s--------------------------------------
                // // 发送外网步骤回调
                // String financeCheckJsonMsg = maintenanceFundsBusinessService.resultNotify(maintenanceFundsBusiness);
                // if (ObjectUtil.isEmpty(financeCheckJsonMsg)) {
                // throw new ServiceException("公维金支出外网回调步骤参数不能为空");
                // }
                // // 步骤回调修改为远程调用
                // try {
                // remoteGwjExpendService.resultNotify(financeCheckJsonMsg, SecurityConstants.INNER).getData();
                // } catch (Exception e) {
                // throw new
                // ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.CONFIRM_ACCEPTANCE) +
                // "支出外网步骤回调一次:" + e.getMessage());
                // }
                // ---------------------------20230829取消步骤回调 e--------------------------------------
                break;
            default:
                // throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.SUBMIT) +
                // "业务状态不一致,请重新提交");
                throw new ServiceException("请先进行确认受理");
        }
        Long stepId;
        try {
            R<GwjConfStep> r = remoteGwjConfigService.selectNextGwjConfStepByFlagId(maintenanceFundsBusiness.getBizFlagId(), maintenanceFundsBusiness.getStepId(), SecurityConstants.INNER);
            if (R.isError(r)) {
                throw new ServiceException(r.getMsg());
            }
            if (ObjectUtil.isNull(r.getData())) {
                throw new ServiceException(r.getMsg());
            }
            stepId = r.getData().getStepId();
        } catch (Exception e) {
            log.error("远程调用 -> [remoteGwjConfigService][selectNextGwjConfStepByFlagId]异常,异常信息: [{}]", e);
            throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.SUBMIT) + "远程调用 -> [remoteGwjConfigService][selectNextGwjConfStepByFlagId]异常");
        }
        Optional.ofNullable(maintenanceFundsBusinessService.updateGwjMaintenanceFundsBusiness(new GwjMaintenanceFundsBusiness() {
            {
                setStepId(stepId);
                setStatus(statusEnum.getCode());
                setBizId(submitRequest.getBizId());
                setCurrentOperId(submitRequest.getCurrentOperId());
                setCurrentOperName(submitRequest.getCurrentOperName());
                setServerStatus(BusinessServerStatusEnum.NORMAL.getCode());
            }
        })).<ServiceException>orElseThrow(() -> {
            throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.SUBMIT) + "GwjMaintenanceFundsBusiness更新失败");
        });
        int insertFlag = maintenanceFundsBusinessLogService.insertGwjMaintenanceFundsBusinessLog(new GwjMaintenanceFundsBusinessLog() {
            {
                setResult(GwjBusinessLogResult.SUBMIT.getCode());
                setContent(submitRequest.getContent());
                setBizId(maintenanceFundsBusiness.getBizId());
                setStepId(maintenanceFundsBusiness.getStepId());
            }
        });
        if (ObjectUtil.equal(FlagStatusEnum.FAL.getCode(), insertFlag)) {
            throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.SUBMIT) + "签署意见GwjMaintenanceFundsBusinessLog新增失败");
        }
        if (ObjectUtil.equal(BusinessStatusEnum.FINANCE_CHECK.getCode(), submitRequest.getStatus())) {
            insertFlag = maintenanceFundsBusinessLogService.insertGwjMaintenanceFundsBusinessLog(new GwjMaintenanceFundsBusinessLog() {
                {
                    setBizId(maintenanceFundsBusiness.getBizId());
                    setResult(GwjBusinessLogResult.FINISH.getCode());
                    setAcceptTime(LocalDateTimeUtil.offset(LocalDateTime.now(), 1, ChronoUnit.SECONDS));
                    try {
                        R<GwjConfStep> r = remoteGwjConfigService.getFinalStep(maintenanceFundsBusiness.getBizFlagId(), SecurityConstants.INNER);
                        if (R.isError(r)) {
                            throw new ServiceException(r.getMsg());
                        }
                        if (ObjectUtil.isNull(r.getData())) {
                            throw new ServiceException(r.getMsg());
                        }
                        setStepId(r.getData().getStepId());
                    } catch (Exception e) {
                        log.error("远程调用 -> [remoteGwjConfigService][getFinalStep]异常,异常信息: [{}]", e);
                        throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.SUBMIT) + "远程调用 -> [remoteGwjConfigService][getFinalStep]异常");
                    }
                }
            });
            if (ObjectUtil.equal(FlagStatusEnum.FAL.getCode(), insertFlag)) {
                throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.SUBMIT) + "签署意见GwjMaintenanceFundsBusinessLog新增失败");
            }
        }
        return FlagStatusEnum.SUC.getCode();
    }

    @Override
    public int confirmReceipt(ConfirmReceiptDTO confirmReceipt) {
        return maintenanceFundsBusinessService.confirmReceipt(confirmReceipt);
    }

    @Override
    public int generateFinancialJournal(Long bizId) {
        GwjMaintenanceFundsBusiness maintenanceFundsBusiness = maintenanceFundsBusinessService.selectGwjMaintenanceFundsBusinessByBusinessId(bizId);
        if (ObjectUtil.equal(FlagStatusEnum.SUC.getCode(), maintenanceFundsBusiness.getFinancialJournalFlag())) {
            throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.GENERATE_FINANCIAL_JOURNAL) + "请勿重复生成财务流水");
        }
        GwjMaintenanceFundsBusinessInfo maintenanceFundsBusinessInfo = maintenanceFundsBusinessInfoService.selectGwjMaintenanceFundsBusinessInfoByBusinessId(bizId);

        // 设置总账参数
        GwjFinanceAccountMain accountMain = new GwjFinanceAccountMain();
        accountMain.setBizId(maintenanceFundsBusiness.getBizId());
        accountMain.setBizNum(maintenanceFundsBusiness.getBizNum());
        accountMain.setBizFlagId(maintenanceFundsBusiness.getBizFlagId());
        accountMain.setBankName(maintenanceFundsBusinessInfo.getBankDeposit());
        accountMain.setBankAccount(maintenanceFundsBusinessInfo.getCollectionAccount());
        accountMain.setIncomeMoney(BigDecimal.ZERO);
        accountMain.setPayMoney(maintenanceFundsBusinessInfo.getTotalSettlementAmount());
        accountMain.setCheckStatus(GwjCheckAccountStatus.NOT_CHECK.getCode());
        accountMain.setCheckType(GwjCheckAccountType.HANDWORK.getCode());
        accountMain.setCompanyName(maintenanceFundsBusinessInfo.getApplicationUnitName());
        accountMain.setProjectName(maintenanceFundsBusiness.getBizName());
        accountMain.setTotalSize(maintenanceFundsBusinessInfo.getTotalInvolvedArea());
        Long areaId = maintenanceFundsBusiness.getAreaId();
        accountMain.setAreaId(areaId);
        // 20230711 hmh 新增 start
        Long bankId = maintenanceFundsBusinessInfo.getBankId();
        accountMain.setBankId(bankId);
        // 查询银行信息
        Map<Long, GwjFinanceBank> bankMap = new HashMap<Long, GwjFinanceBank>();
        GwjFinanceBank bank = remoteGwjFinanceService.selectFinanceBankByBankIdAndAreaId(bankId, areaId, SecurityConstants.INNER).getData();
        if (ObjectUtil.isEmpty(bank)) {
            throw new ServiceException("未获取到对应地区银行！");
        }
        bankMap.put(bank.getBankId(), bank);
        accountMain.setBankAccountType(bankMap.get(bankId).getBankAccountType());
        accountMain.setDealTime(DateUtils.getNowDate());
        accountMain.setCreateBy(SecurityUtils.getLoginUser().getSysUser().getRealName());
        // end
        try {
            R<Integer> r = remoteGwjFinanceService.insertGwjFinanceAccountMain(accountMain, SecurityConstants.INNER);
            if (R.isError(r)) {
                throw new ServiceException(r.getMsg());
            }
            if (ObjectUtil.equal(FlagStatusEnum.FAL.getCode(), r.getData())) {
                throw new ServiceException(r.getMsg());
            }
        } catch (Exception e) {
            log.error("远程调用 -> [remoteGwjFinanceService][insertGwjFinanceAccountMain]异常,异常信息: [{}]", e);
            throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.GENERATE_FINANCIAL_JOURNAL) + "远程调用 -> [remoteGwjFinanceService][insertGwjFinanceAccountMain]异常:" + e.getMessage());
        }
        List<GwjMaintenanceFundsBusinessHouse> maintenanceFundsBusinessHouseList = maintenanceFundsBusinessHouseService.selectGwjMaintenanceFundsBusinessHouseList(new GwjMaintenanceFundsBusinessHouse() {
            {
                setBizId(bizId);
                setSelectFlag(SelectFlagEnum.SELECT.getCode());
            }
        });
        // 处理分账信息
        ArrayList<GwjFinanceAccountDetail> financeAccountDetailList = ListUtil.toList();
        maintenanceFundsBusinessHouseList.forEach(house -> {
            GwjFinanceAccountDetail financeAccountDetail = new GwjFinanceAccountDetail();
            financeAccountDetail.setIncomeMoney(BigDecimal.ZERO);
            financeAccountDetail.setBizId(maintenanceFundsBusiness.getBizId());
            financeAccountDetail.setBizNum(maintenanceFundsBusiness.getBizNum());
            financeAccountDetail.setBizFlagId(maintenanceFundsBusiness.getBizFlagId());
            financeAccountDetail.setHouseCode(house.getHouseCode());
            financeAccountDetail.setPayMoney(house.getActualAllocationMoney());
            financeAccountDetail.setAreaId(maintenanceFundsBusiness.getAreaId());
            financeAccountDetail.setCheckType(GwjCheckAccountType.HANDWORK.getCode());
            financeAccountDetail.setCheckStatus(GwjCheckAccountStatus.NOT_CHECK.getCode());
            financeAccountDetail.setBizFlagIdStr(GwjBusinessFlagType.getInfoByCode(maintenanceFundsBusiness.getBizFlagId()));
            financeAccountDetail.setDealTime(new Date());
            financeAccountDetailList.add(financeAccountDetail);
        });
        // 批量插入分账信息
        try {
            R<Integer> r = remoteGwjFinanceService.insertBatchGwjFinanceAccountDetailInner(financeAccountDetailList, SecurityConstants.INNER);
            if (R.isError(r)) {
                throw new ServiceException(r.getMsg());
            }
            if (ObjectUtil.equal(FlagStatusEnum.FAL.getCode(), r.getData())) {
                throw new ServiceException(r.getMsg());
            }
        } catch (Exception e) {
            log.error("远程调用 -> [remoteGwjFinanceService][insertBatchGwjFinanceAccountDetailInner]异常,异常信息: [{}]", e);
            throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.GENERATE_FINANCIAL_JOURNAL) + "远程调用 -> [remoteGwjFinanceService][insertBatchGwjFinanceAccountDetailInner]异常");
        }
        Optional.ofNullable(maintenanceFundsBusinessService.updateGwjMaintenanceFundsBusiness(new GwjMaintenanceFundsBusiness() {
            {
                setBizId(maintenanceFundsBusiness.getBizId());
                setFinancialJournalFlag(FlagStatusEnum.SUC.getCode());
            }
        })).<ServiceException>orElseThrow(() -> {
            throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.GENERATE_FINANCIAL_JOURNAL) + "GwjMaintenanceFundsBusiness更新异常");
        });
        return FlagStatusEnum.SUC.getCode();
    }

    @Override
    public List<GwjFinanceAccountMain> selectGwjFinanceAccountMainList(RemoteGwjFinanceAccountMainRequest mainRequest) {
        GwjFinanceAccountMain accountMain = new GwjFinanceAccountMain();
        BeanUtil.copyProperties(mainRequest, accountMain);
        try {
            R<List<GwjFinanceAccountMain>> r = remoteGwjFinanceService.selectGwjFinanceAccountMainList(accountMain, SecurityConstants.INNER);
            if (R.isError(r)) {
                throw new ServiceException(r.getMsg());
            }
            if (ObjectUtil.isNull(r.getData()) || CollectionUtil.isEmpty(r.getData())) {
                throw new ServiceException("数据为空");
            }
            return r.getData().stream().map(item -> {
                item.setBizFlagIdStr(GwjBusinessFlagType.getInfoByCode(item.getBizFlagId()));
                item.setCheckTypeStr(GwjCheckAccountType.getInfoByCode(item.getCheckType()));
                item.setCheckStatusStr(GwjCheckAccountStatus.getInfoByCode(item.getCheckStatus()));
                return item;
            }).collect(Collectors.toList());
        } catch (Exception e) {
            log.error("远程调用 -> [remoteGwjFinanceService][selectGwjFinanceAccountMainList]异常: [{}]", e);
            return null;
        }
    }

    /**
     * 获取验收报告
     *
     * @param bizId 业务标识
     * @return {@link AcceptanceReportDTO}
     */
    @Override
    public AcceptanceReportDTO getAcceptanceReport(Long bizId) {
        GwjMaintenanceFundsBusinessInfo gwjMaintenanceFundsBusinessAppropriateInfo = maintenanceFundsBusinessInfoService.selectGwjMaintenanceFundsBusinessInfoByBusinessId(bizId);
        if (ObjectUtil.isNull(gwjMaintenanceFundsBusinessAppropriateInfo)) {
            return null;
        }
        GwjMaintenanceFundsBusiness gwjMaintenanceFundsBusinessAppropriate = maintenanceFundsBusinessService.selectGwjMaintenanceFundsBusinessByBusinessId(bizId);
        if (ObjectUtil.isNull(gwjMaintenanceFundsBusinessAppropriate)) {
            throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.GET_TRANSFORMATION_PLAN) + "GwjMaintenanceFundsBusiness为空");
        }
        GwjMaintenanceFundsBusinessAttachment maintenanceFundsBusinessAttachment = maintenanceFundsBusinessAttachmentService.getGwjMaintenanceFundsBusinessAttachment(new GwjMaintenanceFundsBusinessAttachment() {
            {
                setServerIdentification(gwjMaintenanceFundsBusinessAppropriate.getServerIdentification());
                setServerType(BusinessAttachmentServerTypeEnum.ACCEPTANCE_REPORT.getCode());
                setType(BusinessAttachmentTypeEnum.REPORT.getCode());
            }
        });
        return new AcceptanceReportDTO() {
            {
                setMaintenanceItems(gwjMaintenanceFundsBusinessAppropriateInfo.getMaintenanceItems());
                setConstructionUnitName(gwjMaintenanceFundsBusinessAppropriateInfo.getConstructionUnit());
                setApplicationUnitName(gwjMaintenanceFundsBusinessAppropriateInfo.getApplicationUnitName());
                setProjectBudgetAmount(gwjMaintenanceFundsBusinessAppropriateInfo.getProjectBudgetAmount());
                setProjectBudgetAmountChar(BigDecimalUtils.toChinese(gwjMaintenanceFundsBusinessAppropriateInfo.getProjectBudgetAmount().toString()));
                setAcceptancePersonnelList(new ArrayList<AcceptanceReportRequest.AcceptancePersonnel>());
                if (ObjectUtil.isNotNull(maintenanceFundsBusinessAttachment)) {
                    AcceptanceReportRequest acceptanceReportRequest = JSONUtil.toBean(maintenanceFundsBusinessAttachment.getContent(), AcceptanceReportRequest.class);
                    setDesigner(acceptanceReportRequest.getDesigner());
                    setControlUnit(acceptanceReportRequest.getControlUnit());
                    setProjectOverview(acceptanceReportRequest.getProjectOverview());
                    setAcceptanceContent(acceptanceReportRequest.getAcceptanceContent());
                    setAcceptanceAmount(acceptanceReportRequest.getAcceptanceAmount());
                    setAcceptanceConclusion(acceptanceReportRequest.getAcceptanceConclusion());
                    setConstructionUnit(acceptanceReportRequest.getConstructionUnit());
                    setAttachmentId(maintenanceFundsBusinessAttachment.getAttachmentId());
                    if (ObjectUtil.isNotNull(acceptanceReportRequest.getAcceptancePersonnelList())) {
                        setAcceptancePersonnelList(acceptanceReportRequest.getAcceptancePersonnelList());
                    }
                    setConstructionUnit(acceptanceReportRequest.getConstructionUnit());
                    setCommencementTime(acceptanceReportRequest.getCommencementTime());
                    setSaveTime(acceptanceReportRequest.getSaveTime());
                }
            }
        };
    }

    /**
     * 获取申请拨付报告
     *
     * @param bizId 业务标识
     * @return {@link ApplyAppropriateReportDTO}
     */
    @Override
    public ApplyAppropriateReportDTO getApplyAppropriateReport(Long bizId) {
        GwjMaintenanceFundsBusiness gwjMaintenanceFundsBusiness = maintenanceFundsBusinessService.selectGwjMaintenanceFundsBusinessByBusinessId(bizId);
        if (ObjectUtil.isNull(gwjMaintenanceFundsBusiness)) {
            throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.GET_APPLICATION_REPORT) + "gwjMaintenanceFundsBusiness为空");
        }
        GwjMaintenanceFundsBusinessInfo gwjMaintenanceFundsBusinessInfo = maintenanceFundsBusinessInfoService.selectGwjMaintenanceFundsBusinessInfoByBusinessId(bizId);
        if (ObjectUtil.isNull(gwjMaintenanceFundsBusinessInfo)) {
            throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.GET_APPLICATION_REPORT) + "gwjMaintenanceFundsBusiness为空");
        }
        GwjMaintenanceFundsBusinessCommunity gwjMaintenanceFundsBusinessCommunity = maintenanceFundsBusinessCommunityService.selectGwjMaintenanceFundsBusinessCommunityByBusinessId(bizId);
        if (ObjectUtil.isNull(gwjMaintenanceFundsBusinessCommunity)) {
            throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.GET_APPLICATION_REPORT) + "gwjMaintenanceFundsBusinessCommunity为空");
        }
        GwjMaintenanceFundsBusinessAttachment maintenanceFundsBusinessAttachment = maintenanceFundsBusinessAttachmentService.getGwjMaintenanceFundsBusinessAttachment(new GwjMaintenanceFundsBusinessAttachment() {
            {
                setServerIdentification(gwjMaintenanceFundsBusiness.getServerIdentification());
                setServerType(BusinessAttachmentServerTypeEnum.APPLICATION_APPROPRIATE_REPORT.getCode());
                setType(BusinessAttachmentTypeEnum.REPORT.getCode());
            }
        });

        if (ObjectUtil.isNull(gwjMaintenanceFundsBusinessInfo.getBudgetAppropriationAmount())) {
            gwjMaintenanceFundsBusinessInfo.setBudgetAppropriationAmount(BigDecimal.ZERO);
        }
        if (ObjectUtil.isNull(gwjMaintenanceFundsBusinessInfo.getSecondAppropriationAmount())) {
            gwjMaintenanceFundsBusinessInfo.setSecondAppropriationAmount(BigDecimal.ZERO);
        }
        if (ObjectUtil.isNull(gwjMaintenanceFundsBusinessInfo.getTotalSettlementAmount())) {
            gwjMaintenanceFundsBusinessInfo.setTotalSettlementAmount(BigDecimal.ZERO);
        }
        return new ApplyAppropriateReportDTO() {
            {
                setCommunityName(gwjMaintenanceFundsBusinessCommunity.getCommunityName());
                setRepairCompletionDate(gwjMaintenanceFundsBusinessInfo.getRepairCompletionDate());
                setMaintenanceItems(gwjMaintenanceFundsBusinessInfo.getMaintenanceItems());
                setTotalSettlementAmount(gwjMaintenanceFundsBusinessInfo.getTotalSettlementAmount());
                setBudgetAppropriationAmount(gwjMaintenanceFundsBusinessInfo.getBudgetAppropriationAmount());
                setApplicationUnitName(gwjMaintenanceFundsBusinessInfo.getApplicationUnitName());
                setSecondAppropriationAmount(gwjMaintenanceFundsBusinessInfo.getSecondAppropriationAmount());
                setPayeeName(gwjMaintenanceFundsBusinessInfo.getPayeeName());
                setBankDeposit(gwjMaintenanceFundsBusinessInfo.getBankDeposit());
                setCollectionAccount(gwjMaintenanceFundsBusinessInfo.getCollectionAccount());
                setTotalHouseholds(gwjMaintenanceFundsBusinessInfo.getTotalHouseholds());
                setApplicationUnitName(gwjMaintenanceFundsBusinessInfo.getApplicationUnitName());
                setBudgetAppropriationAmountChar(BigDecimalUtils.toChinese(gwjMaintenanceFundsBusinessInfo.getBudgetAppropriationAmount().toString()));
                setSecondAppropriationAmountChar(BigDecimalUtils.toChinese(gwjMaintenanceFundsBusinessInfo.getSecondAppropriationAmount().toString()));
                setTotalSettlementAmountChar(BigDecimalUtils.toChinese(gwjMaintenanceFundsBusinessInfo.getTotalSettlementAmount().toString()));
                if (ObjectUtil.isNotNull(maintenanceFundsBusinessAttachment)) {
                    ApplyAppropriateReportRequest applyAppropriateReportRequest = JSONUtil.toBean(maintenanceFundsBusinessAttachment.getContent(), ApplyAppropriateReportRequest.class);
                    setAcceptanceUnit(applyAppropriateReportRequest.getAcceptanceUnit());
                    setAcceptanceReportIssuingUnit(applyAppropriateReportRequest.getAcceptanceReportIssuingUnit());
                    setBudgetAppropriationTime(applyAppropriateReportRequest.getBudgetAppropriationTime());
                    setPublicityStartTime(applyAppropriateReportRequest.getPublicityStartTime());
                    setPublicityEndTime(applyAppropriateReportRequest.getPublicityEndTime());
                    setSaveTime(applyAppropriateReportRequest.getSaveTime());
                    setPublicityPlace(applyAppropriateReportRequest.getPublicityPlace());
                    setAttachmentId(maintenanceFundsBusinessAttachment.getAttachmentId());
                }
            }
        };
    }

    /**
     * 查询决算费用分摊清册
     *
     * @param bizId 业务标识
     * @return int
     */
    @Override
    public TotalCostShareListDTO costList(Long bizId, BusinessAttachmentServerTypeEnum businessAttachmentServerTypeEnum) {
        List<CostListDTO> costListDtoS = maintenanceFundsBusinessService.costList(bizId);
        if (ObjectUtil.isNull(costListDtoS)) {
            throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.GET_TOTAL0_COST_SHARE_LIST) + "costListDtoS为空");
        }
        GwjMaintenanceFundsBusiness gwjMaintenanceFundsBusiness = maintenanceFundsBusinessService.selectGwjMaintenanceFundsBusinessByBusinessId(bizId);
        if (ObjectUtil.isNull(gwjMaintenanceFundsBusiness)) {
            throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.GET_TOTAL0_COST_SHARE_LIST) + "gwjMaintenanceFundsBusiness为空");
        }
        GwjMaintenanceFundsBusinessInfo gwjMaintenanceFundsBusinessInfo = maintenanceFundsBusinessInfoService.selectGwjMaintenanceFundsBusinessInfoByBusinessId(bizId);
        GwjMaintenanceFundsBusinessCommunity gwjMaintenanceFundsBusinessCommunity = maintenanceFundsBusinessCommunityService.selectGwjMaintenanceFundsBusinessCommunityByBusinessId(bizId);
        GwjMaintenanceFundsBusinessAttachment maintenanceFundsBusinessAttachment = maintenanceFundsBusinessAttachmentService.getGwjMaintenanceFundsBusinessAttachment(new GwjMaintenanceFundsBusinessAttachment() {
            {
                setServerIdentification(gwjMaintenanceFundsBusiness.getServerIdentification());
                setServerType(businessAttachmentServerTypeEnum.getCode());
                setType(BusinessAttachmentTypeEnum.REPORT.getCode());
            }
        });
        LocalDate saveTime = null;
        Long attachmentId = null;
        if (ObjectUtil.isNotNull(maintenanceFundsBusinessAttachment)) {
            TotalCostShareListRequest totalCostShareListRequest = JSONUtil.toBean(maintenanceFundsBusinessAttachment.getContent(), TotalCostShareListRequest.class);
            if (ObjectUtil.isNotNull(totalCostShareListRequest.getSaveContentList())) {
                for (CostListDTO costListDTO : costListDtoS) {
                    for (int i = 0; i < totalCostShareListRequest.getSaveContentList().size(); i++) {
                        if (ObjectUtil.equal(costListDTO.getHouseCode(), totalCostShareListRequest.getSaveContentList().get(i).getHouseCode())) {
                            costListDTO.setRemark(totalCostShareListRequest.getSaveContentList().get(i).getRemark());
                        }
                    }
                }
                saveTime = totalCostShareListRequest.getSaveTime();
            }
            attachmentId = maintenanceFundsBusinessAttachment.getAttachmentId();
        }
        LocalDate finalSaveTime = saveTime;
        Long finalAttachmentId = attachmentId;
        return new TotalCostShareListDTO() {
            {
                setCommunityName(gwjMaintenanceFundsBusinessCommunity.getCommunityName());
                setMaintenanceItems(gwjMaintenanceFundsBusinessInfo.getMaintenanceItems());
                setTotalSettlementAmount(gwjMaintenanceFundsBusinessInfo.getTotalSettlementAmount());
                setApplicationUnitName(gwjMaintenanceFundsBusinessInfo.getApplicationUnitName());
                setTableDataInfo(PageUtils.getDataTable(costListDtoS));
                setSaveTime(finalSaveTime);
                setAttachmentId(finalAttachmentId);
            }
        };
    }

    @Override
    public List<GwjFinanceAccountDetail> selectGwjFinanceAccountDetailList(RemoteGwjFinanceAccountDetailRequest detailRequest) {
        try {
            R<List<GwjFinanceAccountDetail>> r = remoteGwjFinanceService.getGwjFinanceAccountDetailList(detailRequest, SecurityConstants.INNER);
            if (R.isError(r)) {
                throw new ServiceException(r.getMsg());
            }
            if (ObjectUtil.isNull(r.getData()) || CollectionUtil.isEmpty(r.getData())) {
                throw new ServiceException("数据为空");
            }
            return r.getData().stream().map(item -> {
                item.setBizFlagIdStr(GwjBusinessFlagType.getInfoByCode(item.getBizFlagId()));
                item.setCheckTypeStr(GwjCheckAccountType.getInfoByCode(item.getCheckType()));
                item.setCheckStatusStr(GwjCheckAccountStatus.getInfoByCode(item.getCheckStatus()));
                return item;
            }).collect(Collectors.toList());
        } catch (Exception e) {
            log.error("远程调用 -> [remoteGwjFinanceService][getGwjFinanceAccountDetailList]异常: [{}]", e);
            return null;
        }
    }

    @Override
    public OneTimeNotificationDTO oneTimeNotification(Long bizId) {
        return maintenanceFundsBusinessService.oneTimeNotification(bizId);
    }

    @Override
    public Application4ApprovalDTO getApplication4Approval(Long bizId) {
        return maintenanceFundsBusinessService.getApplication4Approval(bizId);
    }

    @Override
    public Appropriate4ApproveDTO getAppropriate4Approval(Long bizId) {
        return maintenanceFundsBusinessService.getAppropriate4Approval(bizId);
    }

    @Override
    public int cancelReceipt(Long attachmentId) {
        return maintenanceFundsBusinessService.cancelReceipt(attachmentId);
    }

    /**
     * 导出房屋数据
     *
     * @param allocatedAmountRequest
     * @return 楼栋下房屋信息
     */
    @Override
    public List<AllocatedAmountListDTO> exportHouseList(AllocatedAmountRequest allocatedAmountRequest) {
        return maintenanceFundsBusinessService.exportHouseList(allocatedAmountRequest);
    }

    @Override
    public int fallback(SubmitRequest submitRequest) {
        GwjMaintenanceFundsBusiness maintenanceFundsBusiness = maintenanceFundsBusinessService.selectGwjMaintenanceFundsBusinessByBusinessId(submitRequest.getBizId());
        if (ObjectUtil.isNull(maintenanceFundsBusiness)) {
            throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.FALLBACK) + "GwjMaintenanceFundsBusiness为空");
        }
        // 能回退的步骤只有初审跟复审
        BusinessStatusEnum statusEnum;
        BusinessStatusEnum oldStatusEnum = BusinessStatusEnum.transfer(maintenanceFundsBusiness.getStatus());
        switch (oldStatusEnum) {
            // 1.初审提交阶段
            case FIRST_INSTANCE:
                // 删除总账流水跟分类账流水,并且financial_journal_flag归0
                if (ObjectUtil.equal(maintenanceFundsBusiness.getFinancialJournalFlag(), FlagStatusEnum.SUC.getCode())) {
                    try {
                        R<Integer> r = remoteGwjFinanceService.deleteGwjFinanceAccountMain(new GwjFinanceAccountMain() {
                            {
                                setBizId(maintenanceFundsBusiness.getBizId());
                                setBizNum(maintenanceFundsBusiness.getBizNum());
                                setBizFlagId(maintenanceFundsBusiness.getBizFlagId());
                            }
                        }, SecurityConstants.INNER);
                        if (R.isError(r)) {
                            throw new ServiceException(r.getMsg());
                        }
                        if (ObjectUtil.isNull(r.getData()) || ObjectUtil.equal(FlagStatusEnum.FAL.getCode(), r.getData())) {
                            throw new ServiceException("删除总账流水异常");
                        }
                    } catch (Exception e) {
                        log.error("远程调用 -> [remoteGwjFinanceService][deleteGwjFinanceAccountMain]异常: [{}]", e);
                        throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.FALLBACK) + "远程调用 -> [remoteGwjFinanceService][deleteGwjFinanceAccountMain]异常");
                    }
                    try {
                        R<Integer> r = remoteGwjFinanceService.deleteGwjFinanceAccountDetail(new GwjFinanceAccountDetail() {
                            {
                                setBizId(maintenanceFundsBusiness.getBizId());
                                setBizNum(maintenanceFundsBusiness.getBizNum());
                                setBizFlagId(maintenanceFundsBusiness.getBizFlagId());
                            }
                        }, SecurityConstants.INNER);
                        if (R.isError(r)) {
                            throw new ServiceException(r.getMsg());
                        }
                        if (ObjectUtil.isNull(r.getData()) || ObjectUtil.equal(FlagStatusEnum.FAL.getCode(), r.getData())) {
                            throw new ServiceException("删除分类账流水异常");
                        }
                    } catch (Exception e) {
                        log.error("远程调用 -> [remoteGwjFinanceService][deleteGwjFinanceAccountDetail]异常: [{}]", e);
                        throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.FALLBACK) + "远程调用 -> [remoteGwjFinanceService][deleteGwjFinanceAccountDetail]异常");
                    }
                    Optional.ofNullable(maintenanceFundsBusinessService.updateGwjMaintenanceFundsBusiness(new GwjMaintenanceFundsBusiness() {
                        {
                            setBizId(maintenanceFundsBusiness.getBizId());
                            setFinancialJournalFlag(FlagStatusEnum.FAL.getCode());
                        }
                    })).<ServiceException>orElseThrow(() -> {
                        throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.FALLBACK) + "GwjMaintenanceFundsBusiness更新失败");
                    });
                }
                statusEnum = BusinessStatusEnum.TAKE_PARTS;
                // --------------------------20230906 取消 s--------------------------------
                // 支出外网业务回调参数赋值
                // PreAcceptMessage firstInstancePreAcceptMessage = new PreAcceptMessage();
                // firstInstancePreAcceptMessage.setContent(submitRequest.getContent());
                // firstInstancePreAcceptMessage.setAcceptTime(LocalDateTime.now());
                // firstInstancePreAcceptMessage.setOperId(SecurityUtils.getLoginUser().getUserid());
                // firstInstancePreAcceptMessage.setOperName(SecurityUtils.getLoginUser().getUsername());
                // firstInstancePreAcceptMessage.setStepId(maintenanceFundsBusiness.getStepId());
                // firstInstancePreAcceptMessage.setOutServerIdentification(maintenanceFundsBusiness.getOutServerIdentification());
                // if (ObjectUtil.isEmpty(firstInstancePreAcceptMessage)) {
                // throw new ServiceException("外网支出回退步骤参数不能为空");
                // }
                // // 支出外网业务步骤回退
                // try {
                // remoteGwjExpendService.rollbackResultNotify(JSONUtil.toJsonStr(firstInstancePreAcceptMessage),
                // SecurityConstants.INNER);
                //
                // } catch (Exception e) {
                // throw new
                // ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.CONFIRM_ACCEPTANCE) +
                // "支出外网步骤回调一次:" + e.getMessage());
                // }
                // --------------------------20230906 取消 e--------------------------------
                break;
            // 2.复审提交阶段
            case REEXAMINE:
                GwjMaintenanceFundsBusinessInfo maintenanceFundsBusinessInfo = maintenanceFundsBusinessInfoService.selectGwjMaintenanceFundsBusinessInfoByBusinessId(submitRequest.getBizId());
                if (ObjectUtil.equal(AppropriationWayEnum.TWO.getCode(), maintenanceFundsBusinessInfo.getAppropriationWay())) {
                    if (ObjectUtil.equal(FlagStatusEnum.SUC.getCode(), maintenanceFundsBusiness.getFinancialJournalFlag())) {
                        Optional.ofNullable(maintenanceFundsBusinessService.updateGwjMaintenanceFundsBusiness(new GwjMaintenanceFundsBusiness() {
                            {
                                setBizId(maintenanceFundsBusiness.getBizId());
                                setFinancialJournalFlag(FlagStatusEnum.FAL.getCode());
                            }
                        })).<ServiceException>orElseThrow(() -> {
                            throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.FALLBACK) + "GwjMaintenanceFundsBusiness更新失败");
                        });
                        Optional.ofNullable(maintenanceFundsBusinessInfoService.updateGwjMaintenanceFundsBusinessInfo(new GwjMaintenanceFundsBusinessInfo() {
                            {
                                setBizId(maintenanceFundsBusiness.getBizId());
                                setActualAllocatedTime(null);
                                setActualAllocatedSettlementAmount(BigDecimal.ZERO);
                            }
                        })).<ServiceException>orElseThrow(() -> {
                            throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.FALLBACK) + "GwjMaintenanceFundsBusinessInfo更新失败");
                        });
                        try {
                            R<Integer> r = remoteGwjFinanceService.deleteGwjFinanceAccountMain(new GwjFinanceAccountMain() {
                                {
                                    setBizId(maintenanceFundsBusiness.getBizId());
                                    setBizNum(maintenanceFundsBusiness.getBizNum());
                                    setBizFlagId(maintenanceFundsBusiness.getBizFlagId());
                                }
                            }, SecurityConstants.INNER);
                            if (R.isError(r)) {
                                throw new ServiceException(r.getMsg());
                            }
                            if (ObjectUtil.isNull(r.getData()) || ObjectUtil.equal(FlagStatusEnum.FAL.getCode(), r.getData())) {
                                log.error("远程调用响应体 -> [{}]", r);
                                throw new ServiceException("删除总账流水异常");
                            }
                        } catch (Exception e) {
                            log.error("远程调用 -> [remoteGwjFinanceService][deleteGwjFinanceAccountMain]异常: [{}]", e);
                            throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.FALLBACK) + "远程调用 -> [remoteGwjFinanceService][deleteGwjFinanceAccountMain]异常");
                        }
                        try {
                            R<Integer> r = remoteGwjFinanceService.deleteGwjFinanceAccountDetail(new GwjFinanceAccountDetail() {
                                {
                                    setBizId(maintenanceFundsBusiness.getBizId());
                                    setBizNum(maintenanceFundsBusiness.getBizNum());
                                    setBizFlagId(maintenanceFundsBusiness.getBizFlagId());
                                }
                            }, SecurityConstants.INNER);
                            if (R.isError(r)) {
                                throw new ServiceException(r.getMsg());
                            }
                            if (ObjectUtil.isNull(r.getData()) || ObjectUtil.equal(FlagStatusEnum.FAL.getCode(), r.getData())) {
                                log.error("远程调用响应体 -> [{}]", r);
                                throw new ServiceException("删除分类流水异常");
                            }
                        } catch (Exception e) {
                            log.error("远程调用 -> [remoteGwjFinanceService][deleteGwjFinanceAccountDetail]异常: [{}]", e);
                            throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.FALLBACK) + "远程调用 -> [remoteGwjFinanceService][deleteGwjFinanceAccountDetail]异常");
                        }
                    }
                }
                statusEnum = BusinessStatusEnum.FIRST_INSTANCE;
                // --------------------------20230906 取消 s--------------------------------
                // 支出外网业务回调参数赋值
                // PreAcceptMessage reexaminePreAcceptMessage = new PreAcceptMessage();
                // reexaminePreAcceptMessage.setContent(submitRequest.getContent());
                // reexaminePreAcceptMessage.setAcceptTime(LocalDateTime.now());
                // reexaminePreAcceptMessage.setOperId(SecurityUtils.getLoginUser().getUserid());
                // reexaminePreAcceptMessage.setOperName(SecurityUtils.getLoginUser().getUsername());
                // reexaminePreAcceptMessage.setStepId(maintenanceFundsBusiness.getStepId());
                // reexaminePreAcceptMessage.setOutServerIdentification(maintenanceFundsBusiness.getOutServerIdentification());
                // if (ObjectUtil.isEmpty(reexaminePreAcceptMessage)) {
                // throw new ServiceException("外网支出回退步骤参数不能为空");
                // }
                // // 支出外网业务步骤回退
                // try {
                // remoteGwjExpendService.rollbackResultNotify(JSONUtil.toJsonStr(reexaminePreAcceptMessage),
                // SecurityConstants.INNER);
                //
                // } catch (Exception e) {
                // throw new
                // ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.CONFIRM_ACCEPTANCE) +
                // "支出外网步骤回调一次:" + e.getMessage());
                // }
                // --------------------------20230906 取消 e--------------------------------
                break;
            case FINANCE_CHECK:
                // 拨款详情置空
                maintenanceFundsBusinessInfoService.updateGwjMaintenanceFundsBusinessInfo(new GwjMaintenanceFundsBusinessInfo() {
                    {
                        setBizId(maintenanceFundsBusiness.getBizId());
                        setActualArea(BigDecimal.ZERO);
                        setActualRemark("");
                        setActualAllocatedTime(null);
                        setActualAllocatedSettlementAmount(BigDecimal.ZERO);
                    }
                });
                statusEnum = BusinessStatusEnum.REEXAMINE;
                // --------------------------20230906 取消 s--------------------------------
                // 支出外网业务回调参数赋值
                // PreAcceptMessage financeCheckPreAcceptMessage = new PreAcceptMessage();
                // financeCheckPreAcceptMessage.setContent(submitRequest.getContent());
                // financeCheckPreAcceptMessage.setAcceptTime(LocalDateTime.now());
                // financeCheckPreAcceptMessage.setOperId(SecurityUtils.getLoginUser().getUserid());
                // financeCheckPreAcceptMessage.setOperName(SecurityUtils.getLoginUser().getUsername());
                // financeCheckPreAcceptMessage.setStepId(maintenanceFundsBusiness.getStepId());
                // financeCheckPreAcceptMessage.setOutServerIdentification(maintenanceFundsBusiness.getOutServerIdentification());
                // if (ObjectUtil.isEmpty(financeCheckPreAcceptMessage)) {
                // throw new ServiceException("外网支出回退步骤参数不能为空");
                // }
                // --------------------------20230906 取消 e--------------------------------
                // 重置生成财务流水状态
                // Optional.ofNullable(((IGwjMaintenanceFundsBusinessService)AopContext.currentProxy()).updateGwjMaintenanceFundsBusiness(new
                // GwjMaintenanceFundsBusiness() {
                // {
                // setBizId(maintenanceFundsBusiness.getBizId());
                // setFinancialJournalFlag(FlagStatusEnum.FAL.getCode());
                // }
                // })).<ServiceException>orElseThrow(() -> {
                // throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.FALLBACK) +
                // "公共维修资金业务信息更新失败");
                // });
                // 重置生成财务流水状态
                Optional.ofNullable(maintenanceFundsBusinessService.updateGwjMaintenanceFundsBusiness(new GwjMaintenanceFundsBusiness() {
                    {
                        setBizId(maintenanceFundsBusiness.getBizId());
                        setFinancialJournalFlag(FlagStatusEnum.FAL.getCode());
                    }
                })).<ServiceException>orElseThrow(() -> {
                    throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.FALLBACK) + "公共维修资金业务信息更新失败");
                });
                // 重置实际拨款金额与实际拨款时间
                Optional.ofNullable(maintenanceFundsBusinessInfoService.updateGwjMaintenanceFundsBusinessInfo(new GwjMaintenanceFundsBusinessInfo() {
                    {
                        setBizId(maintenanceFundsBusiness.getBizId());
                        setActualAllocatedTime(null);
                        setActualAllocatedSettlementAmount(BigDecimal.ZERO);
                    }
                })).<ServiceException>orElseThrow(() -> {
                    throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.FALLBACK) + "维修资金使用申请工程信息GwjMaintenanceFundsBusinessInfo更新失败");
                });
                // 删除总账流水
                try {
                    R<Integer> r = remoteGwjFinanceService.deleteGwjFinanceAccountMain(new GwjFinanceAccountMain() {
                        {
                            setBizId(maintenanceFundsBusiness.getBizId());
                            setBizNum(maintenanceFundsBusiness.getBizNum());
                            setBizFlagId(maintenanceFundsBusiness.getBizFlagId());
                        }
                    }, SecurityConstants.INNER);
                    if (R.isError(r)) {
                        throw new ServiceException(r.getMsg());
                    }
                    if (ObjectUtil.isNull(r.getData()) || ObjectUtil.equal(FlagStatusEnum.FAL.getCode(), r.getData())) {
                        throw new ServiceException("删除总账流水异常");
                    }
                } catch (Exception e) {
                    log.error("远程调用 -> [remoteGwjFinanceService][deleteGwjFinanceAccountMain]异常: [{}]", e);
                    throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.FALLBACK) + "远程调用 -> [remoteGwjFinanceService][deleteGwjFinanceAccountMain]异常");
                }
                // 重置决算总金额
                Optional.ofNullable(maintenanceFundsBusinessInfoService.updateGwjMaintenanceFundsBusinessInfo(new GwjMaintenanceFundsBusinessInfo() {
                    {
                        setBizId(maintenanceFundsBusiness.getBizId());
                        setActualAllocatedTime(null);
                        setActualAllocatedSettlementAmount(BigDecimal.ZERO);
                    }
                })).<ServiceException>orElseThrow(() -> {
                    throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.FALLBACK) + "维修资金使用申请工程信息GwjMaintenanceFundsBusinessInfo更新失败");
                });
                if (ObjectUtil.equal(Integer.valueOf(GwjCheckAccountStatus.CHECK_SUCCESS.getCode()), maintenanceFundsBusiness.getFinanceCheck())) {
                    Optional.ofNullable(maintenanceFundsBusinessService.updateGwjMaintenanceFundsBusiness(new GwjMaintenanceFundsBusiness() {
                        {
                            setBizId(maintenanceFundsBusiness.getBizId());
                            // 更新财务对账状态
                            setFinanceCheck(Integer.valueOf(GwjCheckAccountStatus.NOT_CHECK.getCode()));
                            // 更新生成总帐流水状态
                            setFinancialJournalFlag(Integer.valueOf(GwjCheckAccountStatus.NOT_CHECK.getCode()));
                        }
                    })).<ServiceException>orElseThrow(() -> {
                        throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.FALLBACK) + "财务对账回退失败");
                    });
                }
                // --------------------------20230906 取消 s--------------------------------
                // 支出外网业务步骤回退
                // try {
                // remoteGwjExpendService.rollbackResultNotify(JSONUtil.toJsonStr(financeCheckPreAcceptMessage),
                // SecurityConstants.INNER);
                //
                // } catch (Exception e) {
                // throw new
                // ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.CONFIRM_ACCEPTANCE) +
                // "支出外网步骤回调一次:" + e.getMessage());
                // }
                // --------------------------20230906 取消 e--------------------------------
                break;
            default:
                throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.FALLBACK) + "业务状态不一致,请重新提交");
        }
        Long stepId;
        try {
            R<GwjConfStep> r = remoteGwjConfigService.selectPreviousGwjConfStepByFlagId(maintenanceFundsBusiness.getBizFlagId(), maintenanceFundsBusiness.getStepId(), SecurityConstants.INNER);
            if (R.isError(r)) {
                throw new ServiceException(r.getMsg());
            }
            if (ObjectUtil.isNull(r.getData())) {
                throw new ServiceException(r.getMsg());
            }
            stepId = r.getData().getStepId();
        } catch (Exception e) {
            log.error("远程调用 -> [remoteGwjConfigService][selectPreviousGwjConfStepByFlagId]异常,异常信息: [{}]", e);
            throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.FALLBACK) + "远程调用 -> [remoteGwjConfigService][selectPreviousGwjConfStepByFlagId]异常");
        }
        List<GwjMaintenanceFundsBusinessLog> maintenanceFundsBusinessLogList = maintenanceFundsBusinessLogService.selectGwjMaintenanceFundsBusinessLogList(new GwjMaintenanceFundsBusinessLog() {
            {
                setStepId(stepId);
                setBizId(maintenanceFundsBusiness.getBizId());
            }
        });
        Optional.ofNullable(maintenanceFundsBusinessLogList).<ServiceException>orElseThrow(() -> {
            throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.FALLBACK) + "GwjMaintenanceFundsBusinessLogList为空");
        });
        GwjMaintenanceFundsBusinessLog maintenanceFundsBusinessLog = maintenanceFundsBusinessLogList.stream().max(Comparator.comparing(GwjMaintenanceFundsBusinessLog::getCreateTime)).get();
        Optional.ofNullable(maintenanceFundsBusinessService.updateGwjMaintenanceFundsBusiness(new GwjMaintenanceFundsBusiness() {
            {
                setStepId(stepId);
                setStatus(statusEnum.getCode());
                setBizId(maintenanceFundsBusiness.getBizId());
                setServerStatus(BusinessServerStatusEnum.FALLBACK.getCode());
                setCurrentOperId(maintenanceFundsBusinessLog.getOperId());
                setCurrentOperName(maintenanceFundsBusinessLog.getOperName());
                // 20230715 hmh 修改财务对账状态 0
                setFinanceCheck(0);
            }
        })).<ServiceException>orElseThrow(() -> {
            throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.FALLBACK) + "GwjMaintenanceFundsBusiness更新失败");
        });
        int insertFlag = maintenanceFundsBusinessLogService.insertGwjMaintenanceFundsBusinessLog(new GwjMaintenanceFundsBusinessLog() {
            {
                setResult(GwjBusinessLogResult.FALLBACK.getCode());
                setContent(submitRequest.getContent());
                setBizId(maintenanceFundsBusiness.getBizId());
                setStepId(maintenanceFundsBusiness.getStepId());
            }
        });
        if (ObjectUtil.equal(FlagStatusEnum.FAL.getCode(), insertFlag)) {
            throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.FALLBACK) + "GwjMaintenanceFundsBusinessLog新增失败");
        }
        return FlagStatusEnum.SUC.getCode();
    }

    // @GlobalTransactional
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int editForm(EditFormRequest editFormRequest) {
        if (ObjectUtil.isNull(editFormRequest.getActualArea())) {
            throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.EDIT_FORM) + "实际面积不能为空");
        }
        GwjMaintenanceFundsBusinessInfo maintenanceFundsBusinessInfo = maintenanceFundsBusinessInfoService.selectGwjMaintenanceFundsBusinessInfoByBusinessId(editFormRequest.getBizId());
        if (ObjectUtil.equal(1, CompareUtil.compare(editFormRequest.getActualAllocatedSettlementAmount(), maintenanceFundsBusinessInfo.getTotalSettlementAmount()))) {
            throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.EDIT_FORM) + "实际拨出金额不能大于决算总金额");
        }
        Optional.ofNullable(maintenanceFundsBusinessInfoService.updateGwjMaintenanceFundsBusinessInfo(new GwjMaintenanceFundsBusinessInfo() {
            {
                setBizId(editFormRequest.getBizId());
                setActualArea(editFormRequest.getActualArea());
                setActualRemark(editFormRequest.getActualRemark());
                setActualAllocatedTime(editFormRequest.getActualAllocatedTime());
                setActualAllocatedSettlementAmount(editFormRequest.getActualAllocatedSettlementAmount());
            }
        })).<ServiceException>orElseThrow(() -> {
            throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.EDIT_FORM) + "GwjMaintenanceFundsBusinessInfo更新失败");
        });
        GwjMaintenanceFundsBusiness maintenanceFundsBusiness = maintenanceFundsBusinessService.selectGwjMaintenanceFundsBusinessByBusinessId(editFormRequest.getBizId());
        if (ObjectUtil.isNull(maintenanceFundsBusiness)) {
            throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.EDIT_FORM) + "GwjMaintenanceFundsBusiness为空");
        }
        try {
            R<Integer> r = remoteGwjFinanceService.updateGwjFinanceAccountMain(new GwjFinanceAccountMain() {
                {
                    setBizId(maintenanceFundsBusiness.getBizId());
                    setBizNum(maintenanceFundsBusiness.getBizNum());
                    setBizFlagId(maintenanceFundsBusiness.getBizFlagId());
                    setDealTime(DateUtil.date(editFormRequest.getActualAllocatedTime()));
                }
            }, SecurityConstants.INNER);
            if (R.isError(r)) {
                throw new ServiceException(r.getMsg());
            }
            if (ObjectUtil.equal(FlagStatusEnum.FAL.getCode(), r.getData())) {
                throw new ServiceException(r.getMsg());
            }
        } catch (Exception e) {
            log.error("远程调用 -> [remoteGwjFinanceService][updateGwjFinanceAccountMain]异常,异常信息: [{}]", e);
            throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.EDIT_FORM) + "远程调用 -> [remoteGwjFinanceService][updateGwjFinanceAccountMain]异常");
        }
        try {
            R<Integer> r = remoteGwjFinanceService.updateGwjFinanceAccountDetail(new GwjFinanceAccountDetail() {
                {
                    setBizId(maintenanceFundsBusiness.getBizId());
                    setBizNum(maintenanceFundsBusiness.getBizNum());
                    setBizFlagId(maintenanceFundsBusiness.getBizFlagId());
                    setDealTime(DateUtil.date(editFormRequest.getActualAllocatedTime()));
                }
            }, SecurityConstants.INNER);
            if (R.isError(r)) {
                throw new ServiceException(r.getMsg());
            }
            if (ObjectUtil.equal(FlagStatusEnum.FAL.getCode(), r.getData())) {
                throw new ServiceException(r.getMsg());
            }
        } catch (Exception e) {
            log.error("远程调用 -> [remoteGwjFinanceService][updateGwjFinanceAccountDetail]异常,异常信息: [{}]", e);
            throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.EDIT_FORM) + "远程调用 -> [remoteGwjFinanceService][updateGwjFinanceAccountDetail]异常");
        }
        return FlagStatusEnum.SUC.getCode();
    }

    /* 
     * 财务对账
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Boolean financeCheck(SubmitRequest submitRequest) {
        // 根据submit方法中的财务对账，单独提取出来进行处理
        GwjMaintenanceFundsBusiness maintenanceFundsBusiness = maintenanceFundsBusinessService.selectGwjMaintenanceFundsBusinessByBusinessId(submitRequest.getBizId());
        if (ObjectUtil.isNull(maintenanceFundsBusiness)) {
            throw new ServiceException("未获取到对应业务信息，请核对后再操作！");
        }
        if (ObjectUtil.notEqual(maintenanceFundsBusiness.getStatus(), submitRequest.getStatus())) {
            throw new ServiceException("业务状态不一致,请重新提交");
        }

        // 支出明细跟总支出比对: 分摊总金额=明细总支出
        GwjMaintenanceFundsBusinessInfo maintenanceFundsBusinessInfo = maintenanceFundsBusinessInfoService.selectGwjMaintenanceFundsBusinessInfoByBusinessId(maintenanceFundsBusiness.getBizId());
        List<GwjMaintenanceFundsBusinessHouse> maintenanceFundsBusinessHouseList = maintenanceFundsBusinessHouseService.selectGwjMaintenanceFundsBusinessHouseList(new GwjMaintenanceFundsBusinessHouse() {
            /**
             *
             */
            private static final long serialVersionUID = -4891838883795052243L;

            {
                setSelectFlag(SelectFlagEnum.SELECT.getCode());
                setBizId(maintenanceFundsBusiness.getBizId());
            }
        });
        BigDecimal actualAllocationMoney = maintenanceFundsBusinessHouseList.stream().map(house -> house.getActualAllocationMoney()).reduce(BigDecimal.ZERO, BigDecimal::add);
        if (ObjectUtil.notEqual(maintenanceFundsBusinessInfo.getActualAllocationAmount(), actualAllocationMoney)) {
            throw new ServiceException("决算总金额和明细支出总金额不一致,请重新提交");
        }
        // 总支出跟总账流水支出金额比对:决算总金额=总账流水支出金额
        BigDecimal payMoney = BigDecimal.ZERO;
        try {
            R<GwjFinanceAccountMain> r = remoteGwjFinanceService.getGwjFinanceAccountMain(new GwjFinanceAccountMain() {
                /**
                 *
                 */
                private static final long serialVersionUID = 6639179154134424211L;

                {
                    setBizId(maintenanceFundsBusiness.getBizId());
                    setBizNum(maintenanceFundsBusiness.getBizNum());
                    setBizFlagId(maintenanceFundsBusiness.getBizFlagId());
                }
            }, SecurityConstants.INNER);
            if (R.isError(r)) {
                throw new ServiceException(r.getMsg());
            }
            if (ObjectUtil.isNull(r.getData())) {
                throw new ServiceException(r.getMsg());
            }
            payMoney = r.getData().getPayMoney();
        } catch (Exception e) {
            log.error("远程调用 -> [remoteGwjFinanceService][getGwjFinanceAccountMain]异常,异常信息: [{}]", e);
            throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.PRE_ACCEPT_EXAMINE) + "远程调用 -> [remoteGwjFinanceService][getGwjFinanceAccountMain]异常");
        }
        if (ObjectUtil.notEqual(maintenanceFundsBusinessInfo.getActualAllocationAmount(), payMoney)) {
            throw new ServiceException("决算总金额和总账流水支出金额不一致,请重新提交");
        }
        // 明细账跟总账比对
        List<GwjFinanceAccountDetail> financeAccountDetailList;
        try {
            R<List<GwjFinanceAccountDetail>> r = remoteGwjFinanceService.getGwjFinanceAccountDetailList(new RemoteGwjFinanceAccountDetailRequest() {
                {
                    setBizId(maintenanceFundsBusiness.getBizId());
                    setBizNum(maintenanceFundsBusiness.getBizNum());
                    setBizFlagId(maintenanceFundsBusiness.getBizFlagId());
                }
            }, SecurityConstants.INNER);
            if (R.isError(r)) {
                throw new ServiceException(r.getMsg());
            }
            if (ObjectUtil.isNull(r.getData()) || CollectionUtil.isEmpty(r.getData())) {
                throw new ServiceException("数据为空");
            }
            financeAccountDetailList = r.getData();
        } catch (Exception e) {
            log.error("远程调用 -> [remoteGwjFinanceService][getGwjFinanceAccountDetailList]异常,异常信息: [{}]", e);
            throw new ServiceException("远程调用 -> [remoteGwjFinanceService][getGwjFinanceAccountDetailList]异常:" + e.getMessage());
        }
        BigDecimal payMoneyDetail = financeAccountDetailList.stream().map(detail -> detail.getPayMoney()).reduce(BigDecimal.ZERO, BigDecimal::add);
        if (ObjectUtil.notEqual(payMoney, payMoneyDetail)) {
            throw new ServiceException("总账流水支出金额和明细流水支出总金额不一致,请重新提交");
        }
        try {
            R<Integer> r = remoteGwjFinanceService.updateGwjFinanceAccountMain(new GwjFinanceAccountMain() {
                /**
                 *
                 */
                private static final long serialVersionUID = -2593443175711875117L;

                {
                    setBizId(maintenanceFundsBusiness.getBizId());
                    setBizNum(maintenanceFundsBusiness.getBizNum());
                    setBizFlagId(maintenanceFundsBusiness.getBizFlagId());
                    setCheckStatus(GwjCheckAccountStatus.CHECK_SUCCESS.getCode());
                    // 对账时间

                    setCheckTime(DateUtils.getNowDate());
                }
            }, SecurityConstants.INNER);
            if (R.isError(r)) {
                throw new ServiceException(r.getMsg());
            }
            if (ObjectUtil.equal(FlagStatusEnum.FAL.getCode(), r.getData())) {
                throw new ServiceException(r.getMsg());
            }
        } catch (Exception e) {
            log.error("远程调用 -> [remoteGwjFinanceService][updateGwjFinanceAccountMain]异常,异常信息: [{}]", e);
            throw new ServiceException("远程调用 -> [remoteGwjFinanceService][updateGwjFinanceAccountMain]异常" + e.getMessage());
        }
        try {
            R<Integer> r = remoteGwjFinanceService.updateGwjFinanceAccountDetail(new GwjFinanceAccountDetail() {
                /**
                 *
                 */
                private static final long serialVersionUID = -7222516608386976110L;

                {
                    setBizId(maintenanceFundsBusiness.getBizId());
                    setBizNum(maintenanceFundsBusiness.getBizNum());
                    setBizFlagId(maintenanceFundsBusiness.getBizFlagId());
                    setCheckStatus(GwjCheckAccountStatus.CHECK_SUCCESS.getCode());
                    // 对账时间
                    setCheckTime(DateUtils.getNowDate());
                }
            }, SecurityConstants.INNER);
            if (R.isError(r)) {
                throw new ServiceException(r.getMsg());
            }
            if (ObjectUtil.equal(FlagStatusEnum.FAL.getCode(), r.getData())) {
                throw new ServiceException(r.getMsg());
            }
        } catch (Exception e) {
            log.error("远程调用 -> [remoteGwjFinanceService][updateGwjFinanceAccountDetail]异常,异常信息: [{}]", e);
            throw new ServiceException("远程调用 -> [remoteGwjFinanceService][updateGwjFinanceAccountDetail]异常:" + e.getMessage());
        }
        // 实际拨出金额与决算总金额对比：实际拨出金额=决算总金额
        if (!maintenanceFundsBusinessInfo.getActualAllocatedSettlementAmount().equals(maintenanceFundsBusinessInfo.getTotalSettlementAmount())) {
            log.error("实际拨出金额与决算总金额不一致");
            throw new ServiceException("实际拨出金额与决算总金额不一致");
        }

        // 修改状态为财务对账
        // maintenanceFundsBusinessService.updateGwjMaintenanceFundsBusiness(new GwjMaintenanceFundsBusiness() {
        // /**
        // *
        // */
        // private static final long serialVersionUID = -4232667440659649452L;
        //
        // {
        // // 修订状态为财务对账
        // setStatus(BusinessStatusEnum.FINANCE_CHECK.getCode());
        // }
        // });
        // 添加记录，记录财务对账操作
        // int insertFlag =
        // 变更状态
        Integer insertFlag = maintenanceFundsBusinessService.updateGwjMaintenanceFundsBusinessCustom(new GwjMaintenanceFundsBusiness() {

            /**
             *
             */
            private static final long serialVersionUID = -2657809779494896814L;
            {
                setBizId(maintenanceFundsBusiness.getBizId());
                // 修改为已对账
                setFinanceCheck(1);
            }
        });
        if (!(insertFlag > 0)) {
            throw new ServiceException("财务状态更新失败！");
        }
        maintenanceFundsBusinessLogService.insertGwjMaintenanceFundsBusinessLog(new GwjMaintenanceFundsBusinessLog() {
            /**
             *
             */
            private static final long serialVersionUID = 6638771188540202319L;
            {
                setResult(GwjBusinessLogResult.SUBMIT.getCode());
                setContent(submitRequest.getContent());
                setBizId(maintenanceFundsBusiness.getBizId());
                setStepId(maintenanceFundsBusiness.getStepId());
            }
        });
        return Boolean.TRUE;
    }

    /* 
     * 案例办结操作
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Boolean businessFinish(SubmitRequest submitRequest) {
        GwjMaintenanceFundsBusiness maintenanceFundsBusiness = maintenanceFundsBusinessService.selectGwjMaintenanceFundsBusinessByBusinessId(submitRequest.getBizId());
        if (ObjectUtil.isNull(maintenanceFundsBusiness)) {
            throw new ServiceException("未获取到对应业务信息！");
        }
        // 判断改业务是否已经进行财务对账
        if (!GwjCheckAccountStatus.CHECK_SUCCESS.getCode().equals(String.valueOf(maintenanceFundsBusiness.getFinanceCheck()))) {
            throw new ServiceException("请先完成财务对账后再进行提交");
        }
        R<JSONObject> r = remoteGwjConfigService.checkNextStepFinish(maintenanceFundsBusiness.getBizFlagId(), maintenanceFundsBusiness.getStepId(), SecurityConstants.INNER);
        // R<GwjConfStep> r = remoteGwjConfigService.getFinalStep(maintenanceFundsBusiness.getBizFlagId(),
        // SecurityConstants.INNER);
        if (R.isError(r) || StringUtils.isNull(r.getData())) {
            throw new ServiceException("未获取到对应步骤信息！");
        }
        JSONObject json = r.getData();
        if (!json.getBoolean("finishStatus")) {
            throw new ServiceException("当前节点下一步骤非办结状态，操作失败！");
        }
        // 获取用于修改的下一个步骤信息
        // GwjConfStep nextStep = (GwjConfStep)json.get("nextStep");
        GwjConfStep nextStep = JSONObject.parseObject(json.getString("nextStep"), GwjConfStep.class);
        Long finishStepId = nextStep.getStepId();
        if (finishStepId == maintenanceFundsBusiness.getStepId()) {
            throw new ServiceException("当前节点已是办结状态，无需重复提交！");
        }
        // 修改业务状态
        maintenanceFundsBusinessService.updateGwjMaintenanceFundsBusiness(new GwjMaintenanceFundsBusiness() {
            /**
             *
             */
            private static final long serialVersionUID = -7244110796210247085L;

            {
                setStepId(finishStepId);
                setStatus(BusinessStatusEnum.FINISH.getCode());
                setBizId(submitRequest.getBizId());
                // setCurrentOperId(submitRequest.getCurrentOperId());
                // setCurrentOperName(submitRequest.getCurrentOperName());
                setCurrentOperId(SecurityUtils.getLoginUser().getUserid());
                setCurrentOperName(SecurityUtils.getLoginUser().getSysUser().getRealName());
                setServerStatus(BusinessServerStatusEnum.FINISH.getCode());
            }
        });
        // 发送外网步骤回调 2023/08/01
        String financeCheckJsonMsg = maintenanceFundsBusinessService.resultNotify(maintenanceFundsBusiness);
        if (ObjectUtil.isEmpty(financeCheckJsonMsg)) {
            throw new ServiceException("公维金支出外网回调步骤参数不能为空");
        }
        // 步骤回调修改为远程调用
        try {
            remoteGwjExpendService.resultNotify(financeCheckJsonMsg, SecurityConstants.INNER).getData();
        } catch (Exception e) {
            throw new ServiceException(GwjEnumUtils.getEnumConstantMsg(MaintenanceFundsErrorEnum.CONFIRM_ACCEPTANCE) + "支出外网步骤回调一次:" + e.getMessage());
        }
        // 新增日志
        maintenanceFundsBusinessLogService.insertGwjMaintenanceFundsBusinessLog(new GwjMaintenanceFundsBusinessLog() {
            /**
             *
             */
            private static final long serialVersionUID = 6638771188540202319L;

            {
                // setResult(GwjBusinessLogResult.SUBMIT.getCode());
                setResult(GwjBusinessLogResult.FINISH.getCode());// 财务对账对标原php做保存结果
                setContent(submitRequest.getContent());
                setBizId(maintenanceFundsBusiness.getBizId());
                setStepId(finishStepId);
            }
        });
        // 基础房屋扣款
        maintenanceFundsBusinessService.baseHouseCharging(maintenanceFundsBusiness.getBizId());
        return Boolean.TRUE;

    }
}
